with System;
with Interfaces, Interfaces.C, Interfaces.C.Extensions, Interfaces.C.Strings;
with Ada.Finalization, Ada.Unchecked_Deallocation, Ada.Unchecked_Conversion;
use System, Interfaces;
use type Interfaces.C.int;
package V8 is
   pragma Linker_Options ("v8.dll");

   subtype int is C.int;

   subtype intptr_t is int;
   -- C99 standard (7.18.1.4  Integer types capable of holding object pointers )

   subtype unsigned is C.unsigned;

   subtype uintptr_t is unsigned;
   -- C99 standard (7.18.1.4  Integer types capable of holding object pointers )

   subtype bool is Interfaces.C.Extensions.bool;
   -- 0 => false, others => true,
   -- use unary operator "-" convert to or convert from ada boolean

   subtype double is C.double;

   subtype char is C.char;

   subtype chars_ptr is Interfaces.C.Strings.chars_ptr;

   subtype char16_t is C.char16_t;

   subtype int8_t is Interfaces.Integer_8;

   subtype uint8_t is Interfaces.Unsigned_8;

   subtype int16_t is Interfaces.Integer_16;

   subtype uint16_t is Interfaces.Unsigned_16;

   subtype int32_t is Interfaces.Integer_32;

   subtype uint32_t is Interfaces.Unsigned_32;

   subtype int64_t is Interfaces.Integer_64;

   subtype uint64_t is Interfaces.Unsigned_64;

   subtype size_t is C.size_t;

   subtype void_ptr is Interfaces.C.Extensions.void_ptr;

   -- Flags that determine what information is placed captured for each
   -- Stack_Frame when grabbing the current stack trace.
   package Stack_Trace_Options is
      type Enum is new uint32_t;

      k_Line_Number : constant Enum := 1;
      k_Column_Offset : constant Enum := k_Line_Number or 2;
      k_Script_Name : constant Enum := 4;
      k_Function_Name  : constant Enum :=  8;
      k_Is_Eval  : constant Enum :=  16;
      k_Is_Constructor  : constant Enum :=  32;
      k_Script_Name_Or_Source_URL  : constant Enum :=  64;
      k_Over_View  : constant Enum :=  k_Line_Number or k_Column_Offset or k_Script_Name or k_Function_Name;
      k_Detailed  : constant Enum :=  k_Over_View or k_Is_Eval or k_Is_Constructor or k_Script_Name_Or_Source_URL;
   end Stack_Trace_Options;

   type Startup_Data is record
      Data            : chars_ptr;
      Compressed_Size : int;
      Raw_Size        : int;
   end record;


   type Extension_Configuration is record
      Count : int;
      Names : Address;
   end record;

   package Access_Type is
      type Enum is (ACCESS_GET, ACCESS_SET, ACCESS_HAS, ACCESS_DELETE, ACCESS_KEYS);
   end Access_Type;

   package GC_Type is
      type Enum is new uint32_t;
      k_Scavenge : constant Enum := 1;
      k_Mark_Sweep_Compact : constant Enum := 2;
      k_All : constant Enum := k_Scavenge or k_Mark_Sweep_Compact;
   end GC_Type;

   package GC_Callback_Flags is
      type Enum is new uint32_t;
      k_Flags : constant Enum := 0;
      k_Flag_Compacted : constant Enum := 1;
   end GC_Callback_Flags;

   package Object_Space is
      type Enum is new uint32_t;
      k_New_Space : constant Enum := 1;
      k_Old_Pointer_Space : constant Enum := 2;
      k_Old_Data_Space : constant Enum := 4;
      k_Code_Space : constant Enum := 8;
      k_Map_Space : constant Enum := 16;
      k_Lo_Space : constant Enum := 32;
      k_All : constant Enum := k_New_Space or k_Old_Pointer_Space or
        k_Old_Data_Space or k_Code_Space or k_Map_Space or k_Lo_Space;
   end Object_Space;

   package Allocation_Action is
      type Enum is new uint32_t;
      k_Allocate : constant Enum := 1;
      k_Free : constant Enum := 2;
      k_All : constant Enum := k_Allocate or k_Free;
   end Allocation_Action;


   package Property_Attribute is
      type Enum is new uint32_t;
      None       : constant Enum := 0;
      ReadOnly : constant Enum := 1;
      DontEnum : constant Enum := 2;
      DontDelete : constant Enum := 4;
   end Property_Attribute;

   package Access_Control is
      type Enum is new uint32_t;
      DEFAULT               : constant Enum := 0;
      ALL_CAN_READ          : constant Enum := 1;
      ALL_CAN_WRITE         : constant Enum := 2;
      PROHIBITS_OVERWRITING : constant Enum := 4;
   end Access_Control;

   package External_Array_Type is
      type Enum is
        (k_Byte_Array,
         k_Unsigned_Byte_Array,
         k_Short_Array,
         k_Unsigned_Short_Array,
         k_Int_Array,
         k_Unsigned_Int_Array,
         k_Float_Array,
         k_Double_Array,
         k_Pixel_Array);
      for Enum use
        (k_Byte_Array           => 1,
         k_Unsigned_Byte_Array  => 2,
         k_Short_Array          => 3,
         k_Unsigned_Short_Array => 4,
         k_Int_Array            => 5,
         k_Unsigned_Int_Array   => 6,
         k_Float_Array          => 7,
         k_Double_Array         => 8,
         k_Pixel_Array          => 9
        );
   end External_Array_Type;

   package String_Write_Hints is
      type Enum is
        (NO_HINTS,
         HINTS_MANY_WRITES_EXPECTED
        );
   end String_Write_Hints;


   package Heap_Graph_Node_Type is
      type Enum is
        (k_Hidden,
         -- Hidden node, may be filtered when shown to user.

         k_Array,
         -- An array of elements.

         k_String,
         -- A string.

         k_Object,
         -- A JS object (except for arrays and strings).

         k_Code,
         -- Compiled code.

         k_Closure,
         -- Function closure.

         k_Reg_Exp,      -- RegExp.

         k_Heap_Number,  -- Number stored in the heap.

         k_Native
         -- Native object (not from V8 heap).
        );
   end Heap_Graph_Node_Type;

   package Heap_Graph_Edge_Type is
      type Enum is
        (k_Context_Variable,
         -- A variable from a function context.

         k_Element,
         -- An element of an array.

         k_Property,
         -- A named object property.

         k_Internal,
         -- A link that can't be accessed from JS,
         -- thus, its name isn't a real property name
         -- (e.g. parts of a ConsString).

         k_Hidden,
         -- A link that is needed for proper sizes
         -- calculation, but may be hidden from user.

         k_Shortcut
         -- A link that must not be followed during
         -- sizes calculation.
        );
   end Heap_Graph_Edge_Type;

   package Heap_Snapshot_Type is
      type Enum is
        (k_Full
         --Heap snapshot with all instances and references.
        );
   end Heap_Snapshot_Type;

   package Heap_Snapshot_Serialization_Format is
      type Enum is
        (k_JSON
         -- See format description near 'Serialize' method.
        );
   end Heap_Snapshot_Serialization_Format;

   package Output_Stream_Output_Encoding is
      type Enum is
        (k_Ascii
         -- 7 - bit ASCII.
        );
   end Output_Stream_Output_Encoding;

   package Output_Stream_Write_Result is
      type Enum is
      (k_Continue,
       k_Abort
      );
   end Output_Stream_Write_Result;

   package Activity_Control_Option is
      -- enum ActivityControl::ControlOption

      type Enum is
        (k_Continue,
         k_Abort
        );
   end Activity_Control_Option;

   package Reg_Exp_Flags is
      type Enum is new uint32_t;
      k_None : constant Enum := 0;
      k_Global : constant Enum :=  1;
      k_Ignore_Case : constant Enum := 2;
      k_Multiline : constant Enum := 4;
   end Reg_Exp_Flags;


   type Heap_Statistics is record
      Total_Heap_Size            : size_t;
      Total_Heap_Size_Executable : size_t;
      Used_Heap_Size             : size_t;
      Heap_Size_Limit            : size_t;
   end record;

   function "-" (B : bool) return Boolean;

   function "not" (B : bool) return Boolean;

   function "-" (B : boolean) return bool;

   Dummy_Bool : bool;
   -- provide convenient to store value returned from bool function

   package Compression_Algorithm is
      type Enum is (k_Uncompressed, k_BZip2);
   end Compression_Algorithm;

end V8;
